<%@page import="java.util.Vector"%>
<%@page import="it.crosato.stage.shared.objects.EntityDefinition"%>
<html>

<head>
<title>CoMeta - Selezione organismi e vie metaboliche</title>
<link type="text/css" rel="stylesheet" href="css/web.css" media="screen" />
<script type="text/javascript" src="./utilities/jquery-1.6.2.min.js"></script>

<script type="text/javascript">
 		$(document).ready(function() {
 			// bottoni per aggiungere e rimuovere
 			$("#addOrganisms").click(function(e) {
 				$("#availableOrganisms option:selected").appendTo($("#chosenOrganisms"));
 			});
 			$("#removeOrganisms").click(function(e) {
 				$("#chosenOrganisms option:selected").appendTo($("#availableOrganisms"));
 			});
 			$("#addPathways").click(function(e) {
 				$("#availablePathways option:selected").appendTo($("#chosenPathways"));
 			});
 			$("#removePathways").click(function(e) {
 				$("#chosenPathways option:selected").appendTo($("#availablePathways"));
 			});
 		});
 		function selectAll() {
 			var org = document.getElementById("chosenOrganisms");
 			var path = document.getElementById("chosenPathways");
			for (var i = 0; i < org.length; i++) {
 				org.options[i].selected=true;
 			}
 			for (var j = 0; j < path.length; j++) {
 				path.options[j].selected=true;
 			}
 			if (org.length < 2 || path.length < 1) {
 				alert("Almeno due organismi e una via metabolica devono essere selezionati.");
				return false;
 			}
 			return true;
 		}
		</script>
</head>

<body>

	<div class="app">

		<div class="title">
			<h1>CoMeta</h1>
		</div>

		<div class="content">
			<div class="side">
				<form action="index.html" method="get">
					<input type="image" src="pics/freccia-sx.png">
				</form>
			</div>

			<div class="box">
				<%
					Boolean error = Boolean.class.cast(request.getAttribute("error"));
					if (!error) {
						@SuppressWarnings("unchecked")
						Vector<EntityDefinition> organisms = (Vector<EntityDefinition>) request.getAttribute("organisms");
						@SuppressWarnings("unchecked")
						Vector<EntityDefinition> pathways = (Vector<EntityDefinition>) request.getAttribute("pathways");
						@SuppressWarnings("unchecked")
						Vector<EntityDefinition> org = (Vector<EntityDefinition>)session.getAttribute("selectedOrganisms");
						if (org==null) {
							org = new Vector<EntityDefinition>();
						}
						@SuppressWarnings("unchecked")
						Vector<EntityDefinition> path = (Vector<EntityDefinition>)session.getAttribute("selectedPathways");
						if (path==null) {
							path = new Vector<EntityDefinition>();
						}
				%>
				<form action="comparison.html" method="post">
					<div class="selectionFrame">
						<div class="selection">
							<h3>Organismi</h3>
							<select multiple="multiple" id="availableOrganisms">
								<%
									for (int i = 0; i < organisms.size(); i++) {
										boolean found = false;
										for (int j=0; j < org.size() && !found; j++) {
											if (organisms.get(i).getId().equals(org.get(j).getId())) {
												found = true;
											}
										}
										if (!found) {
											out.println("<option value=\"" + organisms.get(i).getId()
												+ "---" + organisms.get(i).getDescription() + "\">"
												+ organisms.get(i).getDescription() + "</option>");
										}
									}
								%>
							</select> <br /> <input type="button" value="Aggiungi" id="addOrganisms" />
							<input type="button" value="Rimuovi" id="removeOrganisms" /> <br />
							<select name="orgList" multiple="multiple" id="chosenOrganisms">
							<%
								for (int i = 0; i < org.size(); i++) {
									out.println("<option selected=\"selected\" value=\"" + org.get(i).getId()
										+ "---" + org.get(i).getDescription() + "\">"
										+ org.get(i).getDescription() + "</option>");
								}
							%>
							</select>
						</div>
						<div class="selection">
							<h3>Vie metaboliche</h3>
							<select multiple="multiple" id="availablePathways">
								<%
								for (int i = 0; i < pathways.size(); i++) {
									boolean found = false;
									for (int j=0; j < path.size() && !found; j++) {
										if (pathways.get(i).getId().equals(path.get(j).getId())) {
											found = true;
										}
									}
									if (!found) {
										out.println("<option value=\"" + pathways.get(i).getId()
											+ "---" + pathways.get(i).getDescription() + "\">"
											+ pathways.get(i).getDescription() + "</option>");
									}
								}
								%>
							</select> <br /> <input type="button" value="Aggiungi" id="addPathways" />
							<input type="button" value="Rimuovi" id="removePathways" /> <br />
							<select name="mapList" multiple="multiple" id="chosenPathways">
							<%
								for (int i = 0; i < path.size(); i++) {
									out.println("<option selected=\"selected\" value=\"" + path.get(i).getId()
											+ "---" + path.get(i).getDescription() + "\">"
											+ path.get(i).getDescription() + "</option>");
								}
							%>
							</select>
						</div>
					</div>
					<div class="options">
						<h3>Opzioni</h3>
						<label for="factor">Fattore di influenza reti di Petri</label>
						<%Double factor = Double.class.cast(session.getAttribute("factor"));%>
						<select name="factor" id="factor">
							<option <%if (factor==null || factor==0) {%>selected="selected"<%} %>>0</option>
							<option <%if (factor!=null && factor==10) {%>selected="selected"<%} %>>10</option>
							<option <%if (factor!=null && factor==20) {%>selected="selected"<%} %>>20</option>
							<option <%if (factor!=null && factor==30) {%>selected="selected"<%} %>>30</option>
							<option <%if (factor!=null && factor==40) {%>selected="selected"<%} %>>40</option>
							<option <%if (factor!=null && factor==50) {%>selected="selected"<%} %>>50</option>
							<option <%if (factor!=null && factor==60) {%>selected="selected"<%} %>>60</option>
							<option <%if (factor!=null && factor==70) {%>selected="selected"<%} %>>70</option>
							<option <%if (factor!=null && factor==80) {%>selected="selected"<%} %>>80</option>
							<option <%if (factor!=null && factor==90) {%>selected="selected"<%} %>>90</option>
							<option <%if (factor!=null && factor==100) {%>selected="selected"<%} %>>100</option>
						</select>
						<div class="reaEnz">
							<fieldset>
								<%Boolean enzS = Boolean.class.cast(session.getAttribute("enzS"));%>
								<legend>Insiemi</legend>
								<label for="reaI">reazioni</label>
								<input type="radio"	name="reaEnzI" id="reaI" value="0"
								<% if(enzS==null || enzS==false) { %>
								 	checked="checked" <%} %>>
								<label for="enzI">enzimi</label>
								<input type="radio" name="reaEnzI" id="enzI" value="1"
								<% if(enzS!=null && enzS==true) { %>
								 	checked="checked" <%} %>>
							</fieldset>
							<fieldset>
								<%Boolean enzI = Boolean.class.cast(session.getAttribute("enzI"));%>
								<legend>Reti di Petri</legend>
								<label for="reaP">reazioni</label>
								<input type="radio"	name="reaEnzP" id="reaP" value="0"
								<% if(enzI==null || enzI==false) { %>
								 	checked="checked" <%} %>>
								 <label for="enzP">enzimi</label>
								 <input type="radio" name="reaEnzP"	id="enzP" value="1"
								 <% if(enzI!=null && enzI==true) { %>
								 	checked="checked" <%} %>>
							</fieldset>
						</div>
					</div>
					<!-- 			</form> -->
					<%
						} else {
					%>
					<p>
						Si sono verificati dei problemi nel recupero delle liste di
						organismi e vie metaboliche. <a href="selection.html">Riprova</a>
					</p>
					<%
						}
					%>
				
			</div>

			<div class="side">
				<input type="image" src="pics/freccia-dx.png"
					onclick="return selectAll()">
				</form>
			</div>

		</div>

		<div class="footer">
			<span>Strumento per la comparazione di reti metaboliche</span>
		</div>

	</div>

</body>

</html>